package com.core.service;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;

import com.core.dao.DAOException;
import com.core.dao.DAOFactory;
import com.core.entities.City;

public class CitySrv {
	
	private Connection conn;

	public CitySrv(Connection conn) {
		this.conn = conn;
	}
	
	public List<String> getCitiesNames(){
		List<String> citiesNames = new ArrayList<String>();
		try{
			for(City city : DAOFactory.getInstance().getCityDAO(conn).selectAll())
				citiesNames.add(city.getName());
		}catch(DAOException e){
			e.printStackTrace();
		}
		return citiesNames;
	}
	public List<String> getCities(String stateName){
		List<String> citiesNames = new ArrayList<String>();
		try{
			int stateId = DAOFactory.getInstance().getStateDAO(conn).getByName(stateName).get(0).getId();
			for(City city : DAOFactory.getInstance().getCityDAO(conn).getByStateId(stateId))
				citiesNames.add(city.getName());
		}catch(DAOException e){
			e.printStackTrace();
		}
		return citiesNames;
	}
	public int getCityPK(String cityName){
		try{
			return DAOFactory.getInstance().getCityDAO(conn).getByName(cityName).get(0).getId();
		}catch(DAOException e){
			e.printStackTrace();
		}
		return -1;
	}
	
	

}
